/*
 *                        _oo0oo_
 *                       o8888888o
 *                       88" . "88
 *                       (| -_- |)
 *                       0\  =  /0
 *                     ___/`---'\___
 *                   .' \\|     |// '.
 *                  / \\|||  :  |||// \
 *                 / _||||| -:- |||||- \
 *                |   | \\\  - /// |   |
 *                | \_|  ''\---/''  |_/ |
 *                \  .-\__  '-'  ___/-. /
 *              ___'. .'  /--.--\  `. .'___
 *           ."" '<  `.___\_<|>_/___.' >' "".
 *          | | :  `- \`.;`\ _ /`;.`/ - ` : | |
 *          \  \ `_.   \_ __\ /__ _/   .-` /  /
 *      =====`-.____`.___ \_____/___.-`___.-'=====
 *                        `=---='
 * 
 * 
 *      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 * 
 *            佛祖保佑       永不宕机     永无BUG
 * 
 *        佛曰:  
 *                写字楼里写字间，写字间里程序员；  
 *                程序人员写程序，又拿程序换酒钱。  
 *                酒醒只在网上坐，酒醉还来网下眠；  
 *                酒醉酒醒日复日，网上网下年复年。  
 *                但愿老死电脑间，不愿鞠躬老板前；  
 *                奔驰宝马贵者趣，公交自行程序员。  
 *                别人笑我忒疯癫，我笑自己命太贱；  
 *                不见满街漂亮妹，哪个归得程序员？
 */

/*
 * @Author: zxl
 * @Date: 2020-11-29 15:45:14
 * @LastEditTime: 2020-12-08 17:26:07
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \vue_shop\src\router\index.js
 */

import Vue from 'vue'
import VueRouter from 'vue-router'
import xss from 'xss'
import marked from 'marked'
import 'github-markdown-css'
import Login from '../components/Login.vue'
import Home from '../components/Home.vue'
import Myself from '../components/Myself.vue'
import Logs from '../components/Logs.vue'
import Members from '../components/Members.vue'
import Activites from '../components/Activities.vue'
import ShowMyself from '../components/ShowMyself'
import EditMyself from '../components/EditMyself'
import ShowLogs from '@/components/ShowLogs'
import LogsList from '@/components/LogsList'
import EditLogs from '@/components/EditLogs'
import NewLogs from '@/components/NewLogs'
import ActivitesList from '@/components/ActivitiesList'
import NewActivites from '@/components/NewActivities.vue' 

Vue.use(VueRouter)
Vue.prototype.$xss = xss
Vue.prototype.$marked = marked

const routes = [{
    path: '/',
    redirect: '/login'
  },
  {
    path: '/login',
    component: Login
  },
  {
    path: '/home',
    component: Home,
    redirect: '/myself',
    children: [{
      path: '/myself',
      component: Myself,
      redirect: '/myself/show',
      children: [{
          path: '/myself/show',
          component: ShowMyself
        },
        {
          path: '/myself/edit',
          component: EditMyself
        }
      ]
    }, {
      path: '/logs',
      component: Logs,
      redirect: '/logs/list',
      children: [{
          path: '/logs/list',
          component: LogsList
        },
        {
          path: '/logs/show/:id',
          component: ShowLogs
        }, {
          path: '/logs/edit/:id',
          component: EditLogs
        }, {
          path: '/logs/new',
          component: NewLogs
        }
      ]
    }, {
      path: '/members',
      component: Members
    }, {
      path: '/activites',
      component: Activites,
      redirect:'/activites/list',
      children:[
        {
          path:'/activites/list',
          component: ActivitesList
        },{
          path:'/activites/new',
          component:NewActivites
        }
      ]
    }]
  },
  // {
  //   path: '*',
  //   redirect: '/login'
  // }
]

const router = new VueRouter({
  routes
})

//挂载路由导航守卫
router.beforeEach((to, from, next) => {
  if (to.path === '/login') {
    return next();
  }
  const tokenStr = window.sessionStorage.getItem('token');
  if (!tokenStr) {
    return next('/login');
  }
  next();
});


export default router

